<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../Test/public/js/vendor/DataTables/css/dataTables.bootstrap.css">
<script src="../Test/public/js/vendor/DataTables/js/jquery.dataTables.min.js"></script>
<script src="../Test/public/js/vendor/DataTables/js/dataTables.bootstrap.min.js"></script>
<title>Insert title here</title>
<style type="text/css">
	#myDiv th{
	    text-align: center;
	}
	#myDiv td{
	    text-align: center;
	}
</style>
</head>
<body>
<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>用户信息</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="btn-group" style="margin-bottom:15px;">
                                        <!-- <button class="btn btn-default J_ajax_content_modal" data-href="./fragment/selectSupplier.jsp"><i class="fa fa-filter"></i>查询</button> -->
                                        <button class="btn btn-default J_ajax_content_modal"  data-href="../Test/user/addUser"><i class="fa fa-plus-square-o"></i>添加</button>
                                    </div>
                                    <div class="table-responsive"  id="myDiv">
                                        <table id="example" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th width="80">用户编号</th>
                                                
                                                <th>用户账号</th>
                                                <th>用户密码</th>
                                                <th>用户名称</th>
                                                <th>用户电话</th>
                                                <th>用户邮件</th>
                                                <th>创建时间</th>
                                                <th width="70">备注</th>
                                                <th width="160">操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <c:forEach items="${user}" var="users">
                                                <tr>
	                                                <td onclick="showUsers('${users.id}','${users.username}','${users.password}','${users.realname}','${users.phone}','${users.email}','${users.createtime}')">${users.id}</td>
	                                                <td onclick="showUsers('${users.id}','${users.username}','${users.password}','${users.realname}','${users.phone}','${users.email}','${users.createtime}')">${users.username}</td>
	                                                <td onclick="showUsers('${users.id}','${users.username}','${users.password}','${users.realname}','${users.phone}','${users.email}','${users.createtime}')">${users.password}</td>
	                                                <td onclick="showUsers('${users.id}','${users.username}','${users.password}','${users.realname}','${users.phone}','${users.email}','${users.createtime}')">${users.realname}</td>
	                                                <td onclick="showUsers('${users.id}','${users.username}','${users.password}','${users.realname}','${users.phone}','${users.email}','${users.createtime}')">${users.phone}</td>
	                                                <td onclick="showUsers('${users.id}','${users.username}','${users.password}','${users.realname}','${users.phone}','${users.email}','${users.createtime}')">${users.email}</td>
	                                                <td onclick="showUsers('${users.id}','${users.username}','${users.password}','${users.realname}','${users.phone}','${users.email}','${users.createtime}')">${users.createtime}</td>
	                                                <td onclick="showUsers('${users.id}','${users.username}','${users.password}','${users.realname}','${users.phone}','${users.email}','${users.createtime}')">
	                                                <c:choose>
													    <c:when test="${users.type == 1}">
													       管理员
													    </c:when>
													    <c:when test="${users.type == 2}">
													       技术员
													    </c:when>
													    <c:otherwise>
													        访客
													    </c:otherwise>
													</c:choose> 
	                                                </td>
	                                                <%-- <td onclick="showUsers('${users.id}','${users.username}','${users.password}','${users.realname}','${users.phone}','${users.email}','${users.createtime}')">${users.authorith>1? "禁用" : "正常"}</td>
	                                                <td onclick="showUsers('${users.id}','${users.username}','${users.password}','${users.realname}','${users.phone}','${users.email}','${users.createtime}')">${users.email}</td> --%>
	                                                <td>
	                                                   <button type="button" class="btn btn-info btn-xs J_ajax_content_modal" onclick="del(${users.id})" data-href="../BL/doUpdateUsers"><i class="fa fa-edit"></i>修改</button>
	                                                   <button type="button" class="btn btn-warning btn-xs J_confirm_modal" onclick="del(${users.id})" data-tip="一定要禁用？" 
	                                                   	data-target="../BL/doDeleteUsers"><i class="fa fa-times-circle"></i>禁用
	                                                   </button>
	                                                   <button type="button" class="btn btn-primary btn-xs J_confirm_modal" onclick="del(${users.id})" data-tip="一定要启用？" 
	                                                   	data-target="../BL/doStartUsers"><i class="fa fa-check-circle"></i>启用
	                                                   </button>
	                                               	</td>
                                            	</tr>
                                            </c:forEach>

                                            </tbody>
                                        </table>
                                    </div>
                                    <nav>
                                    </nav>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>

<!-- Modal -->
<div class="modal fade" id="myModalUsers" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">用户查看</h4>
            </div>
            <form class="form-horizontal J_ajaxForm" role="form" method="get" action="#" data-validate="validate">
                
		         <div class="modal-body">
				    <input type="hidden" class="form-control" value="" name="user_id">
				        <div class="form-group">
				            <label class="col-sm-3 control-label">用户账号</label>
				            <div class="col-sm-6">
				                <input type="text" class="form-control" placeholder="用户账号" id="username" name="username" value="" readonly>
				                <p class="help-block">必填</p>
				            </div>
				        </div>
				        <div class="form-group">
				            <label class="col-sm-3 control-label">用户密码</label>
				            <div class="col-sm-6">
				                <input type="text" class="form-control" placeholder="用户密码" id="password" name="password" value="" readonly>
				                <p class="help-block">必填</p>
				            </div>
				        </div>
				        <div class="form-group">
				          <label class="col-sm-3 control-label">用户名称</label>
					          <div class="col-sm-6">
				              	<input type="text" class="form-control" placeholder="用户名称" id="realname" name="realname" value="" readonly>						   
					          </div>
				        </div>
				        
				        <div class="form-group">
				          <label class="col-sm-3 control-label">用户电话</label>
					          <div class="col-sm-6">       	  
				                 <input type="text" class="form-control" id="phone" name="phone" value="" readonly>
					          </div>
				        </div>
				        <div class="form-group">
				            <label class="col-sm-3 control-label">用户邮件</label>
				            <div class="col-sm-6">
				                <input type="text" class="form-control" placeholder="备注" id="email" name="email" readonly></input>
				                <p class="help-block">必填</p>
				            </div>
				        </div>
				    </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-warning" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
	</body>
	<script language="JavaScript">
	function showUsers(user_id,user_name,user_password,user_type,user_state,user_remarks){
		
		$('#username').val(username);
		$('#password').val(password);
		if (user_state >13) {
			$('#user_state').val("禁用");
		} else{
			$('#user_state').val("正常");
		}
		if (user_type == 11) {
			$('#user_type').val('店长');
		} else if (user_type == 12) {
			$('#user_type').val('店员');
		} else {
			$('#user_type').val('会员');
		}
		$('#user_remarks').val(user_remarks);
		$('#myModalUsers').modal('show');
	}
	
	
		var xmlHttp; //Ajax核心对象名称
		function createXMLHttp() { //创建XMLHttpRequest核心对象
		if (window.XMLHttpRequest) { //判断当前使用的浏览器类型
		xmlHttp = new XMLHttpRequest(); //表示当前使用的是FireFox内核的浏览器
		} else {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		}
		function del(i) {
		createXMLHttp(); //建立xmlHttp核心对象
		//设置一个请求，通过地址重写的方式将userid传递到JSP中
		//var userid = document.getElementById("userid").value;
		xmlHttp.open("POST", "../Test/doAjaxDelete?id=" + i);
		xmlHttp.send(null); //发送请求，不传递任何参数
		//document.getElementById("msg").innerHTML = "传输结束";
		}
		function upd(i) {
			createXMLHttp(); //建立xmlHttp核心对象
			//设置一个请求，通过地址重写的方式将userid传递到JSP中
			//var userid = document.getElementById("userid").value;
			xmlHttp.open("POST", "../Test/doUpdateSupplier?id=" + i);
			xmlHttp.send(null); //发送请求，不传递任何参数
			//document.getElementById("msg").innerHTML = "传输结束";
		}
		/* function del(i){
		  var appid = $("#myDiv").data("sid");
	  	  alert(i);
	      location.href="../Test/doDeleteSupplier?id="+i;
	      } */
 
	      $(document).ready(function () {
	          $('#example').DataTable({
	        	  //"dom": 'bInfo',
	        	  //"dom": '<"top"i>rt<"bottom"flp><"clear">',
	        	  //"sDom": '<"top"f>rt<"bottom"lp>',
	        	  //"dom": '<"top"f>rt<"bottom"p><"clear">',
	              //paging: false,
	               //lengthChange: false,
	              //searching: false,
	              //ordering: false,
	              info: false,
	              //bPaginate : false,
	              //bLengthChange : false,
	              //bInfo : false,
	              iDisplayLength : 10,//默认每页显示多少条记录
	              sPaginationType : "full_numbers",
	              scrollX: true,
	              "language": {
	                  url:'../Test/public/js/vendor/DataTables/Chinese.json'
	              }
	          });
	      });
  </script>
</html>